package com.tarena.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.smartstruts.action.Action;
import org.smartstruts.action.ActionForm;

import com.tarena.bo.UserDao;
import com.tarena.util.FormUtils;
import com.tarena.vo.User;

/**
 * 登录验证类
 * 
 * @author WangPeihu
 * @since 05/01/2010
 * @Team [Never give up]
 * 
 */
public class LoginAction extends Action {
	private UserDao ud = new UserDao();

	@Override
	public String execute(ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {
		try {
			User user = new User();
			FormUtils.populate(user, request);
			if (ud.validateUser(user)) {
				HttpSession session = request.getSession();
				User user2 = ud.getUser(user);
				session.setAttribute("user_key", user2);
				return "success";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "fail";
	}
}
